The foreach command loops through the strings obtained from a given command. Wild card characters are allowed since everything following the in keyword is passed to a Bourne shell for execution. Strings can be obtained from any program including the easiest cases echo, ls and cat. The variable name must be of string type, i.e., consisting of both upper case and lower case letters (and possibly _'s and digits).
foreach StringVarName in -command
body of the loop
end
#convert columns 2 and 3 of the following files in log-log format foreach Fname in ls data*.7[0-9] datatest.42 data*.8[4-7] echo $Fname ... read $Fname X:2[0.001:*] Y:3[0.001:*] let X = log(X) let Y = log(Y) save vectors X Y $Fname.log end
for, math function scan, while, macro